/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author agung
 */
public class Barang {

//    private String kodePenerimaan;
    private String namaBarang;
    private int harga;
    private int jumlah;

    public Barang() {
    }
    
    

    public Barang(String namaBarang, int harga, int jumlah) {
        this.namaBarang = namaBarang;
        this.harga = harga;
        this.jumlah = jumlah;
    }
    
    public boolean TerimaBarang() throws SQLException {
        Connection con = KoneksiDB.Koneksi.open();
        Statement stat = con.createStatement();
        String insert = "insert into barang values(SYSDATE,'" + KodePenerimaan() + "', '" + namaBarang + "', "
                + "'" + harga + "', '" + jumlah + "')";
        stat.executeQuery(insert);
        return true;
    }
    
    public String KodePenerimaan(){
        int random1 = (int )(Math.random() * 50 + 1);
        int random2 = (int )(Math.random() * 50 + 1);
        String kode1 = String.valueOf(random1);
        String kode2 = String.valueOf(random2);
        return "T"+kode1+kode2;
    }
    
}
